import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 引入path
import path from 'path'
// 导入element-plus 按需自动导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),

  ],
  server: {
    hmr: true,
    port: 3001,
    proxy: {
      '/api': {
        target: "http://localhost:8081/", //目标代理接口地址
        secure: false,
        changeOrigin: true, //开启代理，在本地创建一个虚拟服务器
        PathRewrite: {
          '/^api': '/api',
        }

      }
    }
  },
  resolve: {
    //配置路径别名
    alias: {
      '@': path.resolve(__dirname, './src'),
    }
  }
})
